<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Events
 *
 * @author Loug S
 */
class Model_Events extends Model_Template {
    //put your code here
    private $selectByName ;
    public function __construct($db){
        parent::__construct($db);
        $sql = 'SELECT e.idUser, u.login, e.nom,e.description, date FROM Events e, Users u
               WHERE e.idUser=u.id AND date >= CURRENT_DATE ORDER BY e.nom' ; 
        $this->selectAll = Controller_Template::$db->prepare($sql);
        
        $sql='SELECT idUser, nom, description, date FROM Events where idUser=?' ;
        $this->selectById=Controller_Template::$db->prepare($sql);
        
        $sql='SELECT idUser, nom, description, date FROM Events where nom=?' ;
        $this->selectByName=Controller_Template::$db->prepare($sql);
        
        $sql='INSERT INTO Events Values(:id,:name,:description,:date)' ;
        $this->insert=Controller_Template::$db->prepare($sql);
    }
    
    public function getByName($nom) {
           $this->selectByName->execute(array($nom));
		return $this->selectByName;
    }
    public function getById($id) {
           $this->selectById->execute(array($id));
           return $this->sselectById->fetchAll() ;
    }
    
    public function getAll() {
        $this->selectAll->execute();
           return $this->selectAll->fetchAll() ;
    }
    
    public function ajouterEvent($id,$nom,$description,$date) {
        $this->selectAll->execute(array(':id' =>$id,':name'=> $name,':description'=>$description,':date'=>$date));
           return $this->selectAll->fetchAll() ;
    }

}
    
    
    


?>
